﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace VersionComparer.DataModel.FileSystem
{
    class ImageFileItemCreator : ComparableItemCreator
    {
        protected override ComparableItem CreateFromValue(ItemId itemId)
        {
            try
            {
                string path = itemId.Name;
                string extension = System.IO.Path.GetExtension(path).ToUpperInvariant();
                if (extension == ".JPG" ||
                    extension == ".GIF" ||
                    extension == ".BMP" ||
                    extension == ".PNG")
                {
                    if (!File.Exists(path))
                        return null;
                    var Image = System.Drawing.Image.FromFile(path);
                    return new ImageFileItem(Image, path);
                }
                else
                    return null;
            }
            catch
            {
                return null;
            }
        }

        public override int Order
        {
            get
            {
                return 10;
            }
        }
    }
}